//数量加方法
function add(num) {
	//修改数量
	var count = parseInt(document.getElementsByName("count")[num].value) + 1;
	document.getElementsByName("count")[num].value = count;

	//获取商品的单价
	var price = parseInt(document.getElementsByName("price")[num].innerText);

	//总金额
	var sum = price * count;
	document.getElementsByName("total")[num].innerText = sum;

	getSum();
}

//数量减方法
function sub(num) {
	var count = parseInt(document.getElementsByName("count")[num].value) - 1;
	if (count < 1) {
		alert("不能再减了");
		return;
	}
	document.getElementsByName("count")[num].value = count;

	//获取商品的单价
	var price = parseInt(document.getElementsByName("price")[num].innerText);

	//总金额
	var sum = price * count;
	document.getElementsByName("total")[num].innerText = sum;

	getSum();
}

getSum()


function getSum() {
	//先获取所有单项商品
	var total = document.getElementsByName("total");
	var sum = 0;
	for (var i = 0; i < total.length; i++) {
		sum += parseInt(total[i].innerText);
	}
	//再去累加计算所有单项商品的总合计
	document.getElementById("allTotal").innerText = sum;

}

function closePage() {
	if (confirm("您确定要关闭本页吗？")) {
		window.opener = null;
		window.open('', '_self');
		window.close();
	}
}
